var t = require;
var e = module;
var o = exports;
var n =
        (this && this.__extends) ||
        (function () {
            var t = function (e, o) {
                return (t =
                    Object.setPrototypeOf ||
                    ({__proto__: []} instanceof Array &&
                        function (t, e) {
                            t.__proto__ = e;
                        }) ||
                    function (t, e) {
                        for (var o in e) e.hasOwnProperty(o) && (t[o] = e[o]);
                    })(e, o);
            };
            return function (e, o) {
                function n() {
                    this.constructor = e;
                }
                t(e, o), (e.prototype = null === o ? Object.create(o) : ((n.prototype = o.prototype), new n()));
            };
        })(),
    r =
        (this && this.__spreadArrays) ||
        function () {
            for (var t = 0, e = 0, o = arguments.length; e < o; e++) t += arguments[e].length;
            var n = Array(t),
                r = 0;
            for (e = 0; e < o; e++) for (var a = arguments[e], i = 0, s = a.length; i < s; i++, r++) n[r] = a[i];
            return n;
        };
Object.defineProperty(o, "__esModule", {value: !0});
var a = t("BootConst"),
    i = t("WX"),
    s = t("AdCtrl"),
    c = t("Platforms"),
    l = t("TableRules"),
    u = (function (t) {
        function e(e, o, n) {
            for (var a = [], i = 3; i < arguments.length; i++) a[i - 3] = arguments[i];
            var s = t.call(this) || this;
            return (
                (s._onLoaded = function () {
                    s.loaded();
                }),
                (s._onClosed = function () {
                    s.clear(), (s.rule = null), (s._callback = null), (s.showing = !1);
                }),
                (s._onHided = function () {
                    s.rule && s.showing && ((s.rule = null), (s._callback = null), (s.showing = !1));
                }),
                (s._onError = function (t) {
                    s.log(JSON.stringify(t), !0), s.error();
                }),
                s.init.apply(s, r([e, o, n], a)) && (s.xys = []),
                s
            );
        }
        return (
            n(e, t),
            (e.prototype.加载中 = function () {
                return "加载中" == this.status;
            }),
            (e.prototype.可显示 = function () {
                return this.ad && "加载成功" == this.status;
            }),
            (e.prototype.clear = function () {
                this.ad &&
                    (this.ad.offLoad && this.ad.offLoad(this._onLoaded),
                    this.ad.offClose && this.ad.offClose(this._onClosed),
                    this.ad.offHide && this.ad.offHide(this._onHided),
                    this.ad.offError && this.ad.offError(this._onError),
                    this.ad.destroy && this.ad.destroy(),
                    (this.ad = null));
            }),
            (e.prototype.delayCreate = function () {
                var t = this;
                this.clear(),
                    c.default.delays.delay({
                        time: l.TableRules.delayCreateTime,
                        action: function () {
                            t.create();
                        }
                    });
            }),
            (e.prototype.create = function () {
                this.clear(),
                    this._createAd() &&
                        ((this.开始加载时间 = new Date().getTime()),
                        this.ad.onLoad && this.ad.onLoad(this._onLoaded),
                        this.ad.onClose && this.ad.onClose(this._onClosed),
                        this.ad.onHide && this.ad.onHide(this._onHided),
                        this.ad.onError && this.ad.onError(this._onError),
                        (this.status = "加载中"),
                        this.初始手动加载 && this.load());
            }),
            (e.prototype.load = function () {
                this.ad && this.ad.load();
            }),
            (e.prototype.callback = function (t) {
                var e = this._callback;
                (this._callback = null), e && e(t);
            }),
            (e.prototype.show = function (t, e) {
                if (
                    ((this.rule = t),
                    (this._callback = e),
                    (this.xys[0] == this.rule.dx &&
                        this.xys[1] == this.rule.dy &&
                        this.xys[2] == this.rule.offsetX &&
                        this.xys[3] == this.rule.offsetY) ||
                        ((this.xys[0] = this.rule.dx),
                        (this.xys[1] = this.rule.dy),
                        (this.xys[2] = this.rule.offsetX),
                        (this.xys[3] = this.rule.offsetY),
                        this.create()),
                    this.update(),
                    this.showing)
                );
                else if ((this.加载中() && this.检查超时(), this.加载中()));
                else {
                    if (!this.检查广告出错再次尝试时间()) return void (e && e(!1));
                    this.delayCreate();
                }
                this.ad || (e && e(!1));
            }),
            (e.prototype.hide = function () {
                this.rule && ((this.rule = null), (this._callback = null), this.update());
            }),
            (e.prototype.update = function () {
                var t = this;
                if (this.rule) {
                    if (this.showing);
                    else if (this.可显示()) {
                        this.showing = !0;
                        var e = this.ad.show(i.default.getAdShowArgs(a.dd.custom, this.adId));
                        e &&
                            e.then &&
                            e
                                .then(
                                    function () {
                                        t.callback(!0);
                                    },
                                    function (e) {
                                        t._onError(e);
                                    }
                                )
                                .catch(function (e) {
                                    t._onError(e);
                                });
                    }
                } else this.showing && ((this.showing = !1), this.可显示() && this.ad.hide());
            }),
            (e.prototype.loaded = function () {
                (this.status = "加载成功"), this.update();
            }),
            (e.prototype.error = function () {
                (this.status = "出错"), this.callback(!1);
            }),
            e
        );
    })(s.default);
o.default = u;
